﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3
{
    public partial class WebForm13 : System.Web.UI.Page
    {
        private dataDataContext dc = new dataDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                this.Repeater_Product.DataSource = this.dc.Products.ToList();
                this.Repeater_Product.DataBind();
          


            }

        }
        protected void Repeater_Product_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HiddenField productID = e.Item.FindControl("productID") as HiddenField;
            var img = this.dc.ImagesPros.Where(i => i.ProductID == Int32.Parse(productID.Value)).Skip(0).Take(1);
            Image image = e.Item.FindControl("image") as Image;
            foreach (var a in img)
            {
                image.ImageUrl = "~/images/Product/" + a.NameImg;
            }
        }
        protected void ButtonSignin_Click(object sender, EventArgs e)
        {

            if (this.TextBoxname.Text != "" && this.TextBoxemail.Text != "" && this.TextBoxnoidung.Text != "")
            {
                Comment cm = new Comment();

                cm.Name = this.TextBoxname.Text;
                cm.Email = this.TextBoxemail.Text;
                cm.Content = this.TextBoxnoidung.Text;

                this.dc.Comments.InsertOnSubmit(cm);
                this.dc.SubmitChanges();

         this.TextBoxnoidung.Text = "đã gửi thành công";
                Response.Redirect("ContactLienhe.aspx");
                      
        }
                
        }
    }
}